// JavaScript Document

var userFlag = 1,AIFlag=2,win=0;
var chessBoardArray = new Array(15);
var chessArray = new Array();
var chessNum = 0;
var selectX,selectY;
var IsIn = function(x){
	"use strict";
    return (x >= 0 && x < 15);
};
var onStep = function(y,x){
	"use strict";
	chessBoardArray[y][x] = userFlag;
	chessArray[chessNum++] = {
			flag:userFlag,
			y:y,
			x:x
	};
	$.ajax({
		type:"POST",
		url:"AIonStepServlet",
		dataType:"text",
		async:false,
		cache:false,
		traditional:true,
		data:{
			"chessArray" : JSON.stringify(chessArray),
			"chessNum" : chessNum,
			"AIFlag" : AIFlag,
			"userFlag" : userFlag,
		},
		success:function(data){
			data = eval('('+data+')');
			win = data.win;
			selectX = data.x;
			selectY = data.y;
			chessBoardArray[selectY][selectX] = AIFlag;
			chessArray[chessNum++] = {
					flag:AIFlag,
					y:selectY,
					x:selectX
			};
		},
		error:function(){
			alert('与服务器失去通信!');
			initChessBoard();
		}
	});
};